var app=getApp(),that
Page({
  data:{
    page:1,
    limit:10,
    carNewsData:[],
    sLoadMore: true,
    isJzz: false,
    isJzwb: false
  },
  onLoad:function(opt){
    that=this
  },
  onReady:function(res){

  },
  onShow:function(res){
    that.getCarNews()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (that.data.isLoadMore) {
      that.getCarNews()
    } else {
      that.setData({
        isJzwb: true,
        isJzz: false
      })
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },
  getCarNews:function(e){
    app.getData({
      url: app.api.getCarNews(that.data.page, that.data.limit),
      ok:function(res){
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            if (that.data.page == 1) {
              that.data.carNewsData = []
            }
            if (res.data.list.length < that.data.limit) {
              that.setData({
                carNewsData: that.data.carNewsData.concat(res.data.list),
                isLoadMore: false
              })
            } else {
              that.setData({
                carNewsData: that.data.carNewsData.concat(res.data.list),
                isLoadMore: true,
                page: that.data.page + 1
              })
            }
          }
        }
      }
    })
  },
  itemClick: function (e) {
    wx.navigateTo({
      url: '../../pages/newsDetails/newsDetails?item=' + JSON.stringify(e.currentTarget.dataset.item),
    })
  }
})